home *** CD-ROM | disk | FTP | other *** search
/ Shirley Barber's Fairies: Create, Paint & Play / Fairies.iso / pc / Files / Intro.dxr / Internal_10_Change Resolution & Loop for X Seconds.ls < prev    next >
Encoding:
Text File  |  2003-10-03  |  6.1 KB  |  178 lines

  1. property myTimeOut, myRes, myDepth, myXRes, myYRes, myTimeUnit, myTimeOutFrame, myImmediateJump, myStartFrame, myStartTicks, myEndFrame
  2. global scrWidth, scrHeight, scrDepth
  3.  
  4. on beginSprite me
  5.   Initialize(me)
  6. end
  7.  
  8. on exitFrame me
  9.   CheckTimeOut(me)
  10. end
  11.  
  12. on enterFrame me
  13.   if the platform contains "Windows,32" then
  14.     case myRes of
  15.       "640x480":
  16.         myXRes = 640
  17.         myYRes = 480
  18.       "800x600":
  19.         myXRes = 800
  20.         myYRes = 600
  21.       "1024x768":
  22.         myXRes = 1024
  23.         myYRes = 768
  24.     end case
  25.     if (scrWidth = baScreenInfo("width")) and (scrHeight = baScreenInfo("height")) and (scrDepth = baScreenInfo("depth")) then
  26.       Ok = baSetDisplay(myXRes, myYRes, myDepth, "temp", 0)
  27.     else
  28.       go(the frame + 1)
  29.     end if
  30.   end if
  31. end
  32.  
  33. on Initialize me
  34.   thisSprite = sprite(the currentSpriteNum)
  35.   myStartFrame = thisSprite.startFrame
  36.   myEndFrame = thisSprite.endFrame
  37.   if symbolp(myTimeOutFrame) then
  38.     case myTimeOutFrame of
  39.       #previous:
  40.         jumpToFrame = marker(-1)
  41.       #loop:
  42.         jumpToFrame = marker(0)
  43.       #next:
  44.         jumpToFrame = marker(1)
  45.     end case
  46.   else
  47.     jumpToFrame = marker(myTimeOutFrame)
  48.   end if
  49.   myStartTicks = the ticks
  50.   case myTimeUnit of
  51.     "Seconds":
  52.       myTimeOut = myTimeOut * 60
  53.     "Minutes":
  54.       myTimeOut = myTimeOut * 60 * 60
  55.     "Hours":
  56.       myTimeOut = myTimeOut * 60 * 60 * 60
  57.   end case
  58.   myTimeOut = myTimeOut + myStartTicks
  59.   myTimeOutFrame = jumpToFrame
  60.   myImmediateJump = myImmediateJump = "jump immediately"
  61. end
  62.  
  63. on CheckTimeOut me
  64.   if the ticks > myTimeOut then
  65.     if myImmediateJump or (the frame = myEndFrame) then
  66.       go(myTimeOutFrame)
  67.     end if
  68.   else
  69.     if the frame = myEndFrame then
  70.       go(myStartFrame)
  71.     end if
  72.   end if
  73. end
  74.  
  75. on substituteStrings me, parentString, childStringList
  76.   i = childStringList.count()
  77.   repeat while i
  78.     tempString = EMPTY
  79.     dummyString = childStringList.getPropAt(i)
  80.     replacement = childStringList[i]
  81.     lengthAdjust = dummyString.char.count - 1
  82.     repeat while 1
  83.       position = offset(dummyString, parentString)
  84.       if not position then
  85.         parentString = tempString & parentString
  86.         exit repeat
  87.         next repeat
  88.       end if
  89.       if position <> 1 then
  90.         tempString = tempString & parentString.char[1..position - 1]
  91.       end if
  92.       tempString = tempString & replacement
  93.       delete parentString.char[1..position + lengthAdjust]
  94.     end repeat
  95.     i = i - 1
  96.   end repeat
  97.   return parentString
  98. end
  99.  
  100. on ErrorAlert me, theError, Data
  101.   behaviorName = string(me)
  102.   delete word 1 of behaviorName
  103.   delete char -30001 of behaviorName
  104.   delete char -30001 of behaviorName
  105.   case theError of
  106.     #invalidChannel:
  107.       if the runMode = "Author" then
  108.         terror1 = "BEHAVIOR ERROR: Frame ^0, Sprite ^1"
  109.         terror1 = substituteStrings(me, terror1, ["^0": the frame, "^1": the currentSpriteNum])
  110.         terror2 = "Behavior ^0 should be attached to the frame script channel."
  111.         terror2 = substituteStrings(me, terror2, ["^0": behaviorName])
  112.         terror3 = "Current Channel = ^0"
  113.         terror3 = substituteStrings(me, terror3, ["^0": Data])
  114.         alert(terror1 & RETURN & RETURN & terror2 & RETURN & RETURN & terror3)
  115.         abort()
  116.       end if
  117.     #missingMarker:
  118.       if the runMode = "Author" then
  119.         terror1 = "BEHAVIOR ERROR: Frame ^0, Sprite ^1"
  120.         terror1 = substituteStrings(me, terror1, ["^0": the frame, "^1": the currentSpriteNum])
  121.         terror2 = "Frame behavior ^0 is set to jump to marker ^1. " & "This marker cannot be found. " & " Choose a valid marker in the Behavior Parameters dialog."
  122.         terror2 = substituteStrings(me, terror2, ["^0": behaviorName, "^1": myTimeOutFrame])
  123.         terror3 = "In the meantime, frame ^0 will be used instead."
  124.         terror3 = substituteStrings(me, terror3, ["^0": Data])
  125.         alert(terror1 & RETURN & RETURN & terror2 & RETURN & RETURN & terror3)
  126.       end if
  127.     #endlessLoop:
  128.       if the runMode = "Author" then
  129.         if symbolp(myTimeOutFrame) then
  130.           case myTimeOutFrame of
  131.             #previous:
  132.               jumpToFrame = marker(-1)
  133.             #loop:
  134.               jumpToFrame = marker(0)
  135.             #next:
  136.               jumpToFrame = marker(1)
  137.           end case
  138.         else
  139.           jumpToFrame = marker(myTimeOutFrame)
  140.         end if
  141.         terror1 = "BEHAVIOR ERROR: Frame ^0, Sprite ^1"
  142.         terror1 = substituteStrings(me, terror1, ["^0": the frame, "^1": the currentSpriteNum])
  143.         terror2 = "Frame behavior ^0 is set to jump to marker ^1 (frame ^2 ). " & "  This is within the span of the behavior and will cause an endless loop."
  144.         terror2 = substituteStrings(me, terror2, ["^0": behaviorName, "^1": myTimeOutFrame, "^2": jumpToFrame])
  145.         terror3 = "Frame ^0 will be used instead."
  146.         terror3 = substituteStrings(me, terror3, ["^0": Data])
  147.         alert(terror1 & RETURN & RETURN & terror2 & RETURN & RETURN & terror3)
  148.       end if
  149.   end case
  150. end
  151.  
  152. on isOKToAttach me, aSpriteType, aSpriteNum
  153.   tisok = 0
  154.   if aSpriteType = #script then
  155.     tisok = 1
  156.   end if
  157.   return tisok
  158. end
  159.  
  160. on getPropertyDescriptionList me
  161.   nextMarker = nextMarker(me)
  162.   return [#myRes: [#comment: "Change Resolution to", #format: #string, #range: ["640x480", "800x600", "1024x768"], #default: "800x600"], #myDepth: [#comment: "Colour Depth", #format: #integer, #range: ["8", "16", "24"], #default: "16"], #myTimeOut: [#comment: "Loop over selected frames for...", #format: #integer, #range: [#min: 1, #max: 120], #default: 30], #myTimeUnit: [#comment: EMPTY, #format: #string, #range: ["Ticks", "Seconds", "Minutes", "Hours"], #default: "Seconds"], #myTimeOutFrame: [#comment: "... " & "then jump to marker", #format: #marker, #default: nextMarker], #myImmediateJump: [#comment: "When the time is up", #format: #string, #range: ["complete the loop", "jump immediately"], #default: "jump immediately"]]
  163. end
  164.  
  165. on nextMarker me
  166.   labelString = the labelList
  167.   delete char -30000 of labelString
  168.   markerCount = the number of lines in labelString
  169.   theFrame = the frame
  170.   repeat with i = 1 to markerCount
  171.     theMarker = line i of labelString
  172.     markerFrame = marker(theMarker)
  173.     if theFrame < markerFrame then
  174.       return theMarker
  175.     end if
  176.   end repeat
  177. end
  178.